/*
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2023-08-05 22:12:09
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2023-08-06 14:21:09
 */
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { WEB_SALE_VALUE } from '../config/constant';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
    constructor() {
        super({
            jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
            ignoreExpiration: false,
            secretOrKey: WEB_SALE_VALUE,
        });
    }

    // JWT验证 - Step 4: 被守卫调用
    async validate(payload: any) {
        console.log(`JWT验证 - Step 4: 被守卫调用`,payload.info);
        const info = payload.info;
        const sub=payload.sub;
        return {
            info,
            sub
        };
    }
}